/**
 * Created by yesi on 15/5/16.
 */

var common = require("./common/common");

function route(pathname,handle,postData,response) {
    var ext = pathname.match(/(\.[^.]+|)$/)[0];
    console.log("About to route a request for " + pathname);
    if (ext==".html"||ext==".js"||ext=='.css'){
        handle["static"](pathname,response);
    }
    else if (typeof handle[pathname] === 'function') {
        handle[pathname](postData,response);
    } else {
        console.log("No request handler found for " + pathname);
        common.write404(response);
    }
}

exports.route = route;
